<?php
/**
 * Page that provides an interface uploading profile a image
 * 
 */
require_once '../dbms_university_courses_mvc/Connection.php';
$errors = "";
if (isset ( $_POST ['submitted'] )) {
	if ($_FILES ["file"] ["type"] == "image/jpeg" || $_FILES ["file"] ["type"] == "image/pjpeg") {
		if ($_FILES ["file"] ["error"] > 0) {
			$errors .= "Error: " . $_FILES ["file"] ["error"] . "<br />";
		} else {
			$success = "Image Uploaded";
			?>
<h2>Success! <?php
			echo $success;
			?></h2>
<br />
<script type="text/javascript">
window.parent.refreshImage();
</script>
<?php
			echo "File: " . $_FILES ["file"] ["name"] . "<br />";
			//echo "Type: " . $_FILES["file"]["type"] . "<br />";
			echo "Size: " . ($_FILES ["file"] ["size"] / 1024) . " Kb<br />";
			//echo "Stored in: " . $_FILES["file"]["tmp_name"];
			?>
            <?php
			copy ( $_FILES ["file"] ["tmp_name"], "../profile_images/" . $_SESSION ['profile_id'] . ".jpg" ) or die ( "Could not copy" );
		}
	} else {
		$errors .= "Error: " . $_FILES ["file"] ["type"] . " is not a valid file type. The script file extension should be .jpg.<br />";
	}
	echo $errors;
}
?>
<form
	action="image_uploader.php"
	method="post" enctype="multipart/form-data"
>
<table>
	<tr>
		<td align="left">
		Preferred Dimensions: 200px X 200px (jpg only)</td>
	</tr>
	<tr>
		<td><input type="file" id="file" name="file" /></td>
		<td><input type="hidden" value="1" name="submitted" id="submitted" />
		<input type="submit" id="uploadImage" value="Upload Image" /></td>
	</tr>
</table>
</form>